package com.panda.web.mapper.product;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.panda.web.entity.product.OpenidProduct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户，产品关联Mapper接口
 * 
 * @author cpanda
 * @date 2025-03-03
 */
@Mapper
public interface OpenidProductMapper extends BaseMapper<OpenidProduct> {

    @Select("select * from openid_product where openid =#{openid} and product_id =#{productId}")
    OpenidProduct findByProductIdAndOpenId(@Param("openid") String openid, @Param("productId")Long productId);

    @Select("select * from openid_product where openid =#{openid} and product_id =#{productId} and status ='0'")
    OpenidProduct findByProductIdAndOpenIdAndStatus(@Param("openid") String openid, @Param("productId")Long productId);
    @Select("select product_id from openid_product where openid =#{openid} and status =#{status} and product_id!=5 and product_id!=6 and product_id!=7 and product_id!=10 and product_id!=11")
    List<Long> findByOpenid(@Param("openid")String openid,@Param("status") String status); //是否开通不添加 id = 5的

    @Select("select * from openid_product where openid =#{openid} and status =#{status}  and product_id!=6 and product_id!=7 and product_id!=10 and product_id!=11")
    List<OpenidProduct> findByOpenidList(@Param("openid")String openid,@Param("status") String status);

    @Select("select * from openid_product where openid =#{openid} and status =#{status} and product_id!=5 and product_id!=7 and product_id!=10 and product_id!=11 ")
    List<OpenidProduct> findOpenidByPuroduct(@Param("openid")String openid,@Param("status") String status); //是否开通不添加 id = 5的
    @Select("select * from openid_product where status =#{status} and product_id !=#{productId} and product_id !=5")
    List<OpenidProduct> findAllProducts(@Param("status")String status, @Param("productId")Long productId);

    @Select("select count(*) from openid_product where status ='0' and product_id = 1  ")
    int selectListAndPAAndStatus();//购买测评报告未退款的数量
    @Select("select product_id from openid_product where openid =#{openid} and status =#{status} and product_id!=5  ")
    List<Long> findByOpenidByAi(@Param("openid")String openid,@Param("status") String status);


    @Select("select count(*) from openid_product where status ='0' and product_id = 2 or product_id = 3 or product_id = 4 or product_id = 8 or product_id = 9")
    int selectListAIAndStatus();//购买Ai生成未退款的数量
    @Select("select count(*) from openid_product where status ='0' and product_id = 2 or product_id = 3 or product_id = 4 or product_id = 8 or product_id = 9 order by creation_time desc")
    List<OpenidProduct> findByOpenidAndOTFEN(String openid);
}
